<template>
	<view class="addBuilding">
		<f-navbar :title="title" :iconLeft="true" />
		<view class="addBuilding-content ff-bg-fff ff-font-14 ff-color-222 ff-margin-12 ff-border-radius-10">
			<view class="ff-font-16 ff-padding-15 ff-font-weight-600 ff-border-bottom">建筑物基本信息</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑物名称</view>
				<input class="ff-text-right" placeholder="请输入" placeholder-style="color:#999" type="text"
					v-model.trim="addBuilds.buildingName" />
			</view>
			<view>
				<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
					<view class="companyInfo-content-title ff-color-999">建筑物类型</view>
					<view>
						<view class="ff-flex" @click="buildingTypeClick">
							<view v-if="addBuilds.buildingNewTypeTopid == ''">请选择</view>
							<view v-else class="ff-line-height-1-3">{{ buildingTypeName }}</view>
							<u-icon color="#999" name="arrow-right"></u-icon>
						</view>
					</view>
				</view>
				<u-select v-model="buildingTypeState" label-name="typeName" value-name="id"
					:safe-area-inset-bottom="true" @confirm="confirmUnit" :list="buildingTypeList"></u-select>
			</view>
			<view v-if="buildingPurposeList1">
				<view v-if="buildingPurposeList1.length > 0">
					<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
						<view class="companyInfo-content-title ff-color-999">建筑物用途</view>
						<view>
							<view class="ff-flex" @click="buildingPurposeClick1">
								<view v-if="buildingPurposeName1 == ''">请选择</view>
								<view class="ff-text-right ff-line-height-1-3" v-else style="width: 430rpx;">
									{{ buildingPurposeName1 }}
								</view>
								<u-icon color="#999" name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
					<u-select v-model="buildingPurposeState1" label-name="name" value-name="id"
						:safe-area-inset-bottom="true" @confirm="confirmPurpose1"
						:list="buildingPurposeList1"></u-select>
				</view>
			</view>
			<view v-if="buildingPurposeList2">
				<view v-if="buildingPurposeList2.length > 0">
					<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
						<view class="companyInfo-content-title ff-color-999"></view>
						<view>
							<view class="ff-flex" @click="buildingPurposeClick2">
								<view v-if="buildingPurposeName2 == ''">请选择</view>
								<view class="ff-text-right ff-line-height-1-3" v-else style="width: 430rpx;">
									{{ buildingPurposeName2 }}
								</view>
								<u-icon color="#999" name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
					<u-select v-model="buildingPurposeState2" :safe-area-inset-bottom="true" label-name="name"
						value-name="id" @confirm="confirmPurpose2" :list="buildingPurposeList2"></u-select>
				</view>
			</view>
			<view v-if="buildingPurposeList3">
				<view v-if="buildingPurposeList3.length > 0">
					<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
						<view class="companyInfo-content-title ff-color-999"></view>
						<view>
							<view class="ff-flex" @click="buildingPurposeClick3">
								<view v-if="buildingPurposeName3 == ''">请选择</view>
								<view class="ff-text-right ff-line-height-1-3" v-else style="width: 430rpx;">
									{{ buildingPurposeName3 }}
								</view>
								<u-icon color="#999" name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
					<!-- 单位类型弹框 -->
					<u-select v-model="buildingPurposeState3" :safe-area-inset-bottom="true" label-name="name"
						value-name="id" @confirm="confirmPurpose3" :list="buildingPurposeList3"></u-select>
				</view>
			</view>
			<view v-if="buildingPurposeList4">
				<view v-if="buildingPurposeList4.length > 0">
					<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
						<view class="companyInfo-content-title ff-color-999"></view>
						<view>
							<view class="ff-flex" @click="buildingPurposeClick4">
								<view v-if="buildingPurposeName4 == ''">请选择</view>
								<view class="ff-text-right ff-line-height-1-3" v-else style="width: 430rpx;">
									{{ buildingPurposeName4 }}
								</view>
								<u-icon color="#999" name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
					<u-select v-model="buildingPurposeState4" :safe-area-inset-bottom="true" label-name="name"
						value-name="id" @confirm="confirmPurpose4" :list="buildingPurposeList4"></u-select>
				</view>
			</view>

			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑物地址</view>
				<view>
					<view class="ff-flex ff-text-right" @click="unitRegisterAddress">
						<view v-if="addBuilds.buildingAddr == ''">请选择</view>
						<view style="width: 430rpx;" class="ff-line-height-1-3" v-else>{{ addBuilds.buildingAddr }}
						</view>
						<u-icon color="#999" name="map-fill"></u-icon>
					</view>
				</view>
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑高度(米)</view>
				<input class="ff-text-right" placeholder="请输入" placeholder-style="color:#999" type="digit"
					v-model.trim="addBuilds.buildingHeight" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑物面积(m²)</view>
				<input class="ff-text-right" placeholder="请输入" placeholder-style="color:#999" type="digit"
					v-model.trim="addBuilds.buildingArea" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑地上层数(层)</view>
				<input class="ff-text-right" placeholder="请输入" placeholder-style="color:#999" type="number"
					v-model.trim="addBuilds.buildingUpLayers" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">建筑地下层数(层)</view>
				<input class="ff-text-right" placeholder="请输入" placeholder-style="color:#999" type="number"
					v-model.trim="addBuilds.buildingDownLayers" />
			</view>
		</view>
		<view class="addBuilding-content ff-bg-fff ff-font-14 ff-color-222 ff-margin-12 ff-border-radius-10">
			<view class="ff-font-16 ff-padding-15 ff-font-weight-600 ff-border-bottom">人员信息</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">消防安全管理人姓名</view>
				<input v-model.trim="addBuilds.fireManageName" class="ff-text-right" placeholder="请输入"
					placeholder-style="color:#999" type="text" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">消防安全管理人手机号</view>
				<input v-model.trim="addBuilds.fireManagePhone" maxlength="11" class="ff-text-right" placeholder="请输入"
					placeholder-style="color:#999" type="number" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">消防安全责任人姓名</view>
				<input v-model.trim="addBuilds.fireDutyName" class="ff-text-right" placeholder="请输入"
					placeholder-style="color:#999" type="text" />
			</view>
			<view class="ff-flex-between ff-align-items-one ff-border-bottom ff-padding-15">
				<view class="companyInfo-content-title ff-color-999">消防安全责任人手机号</view>
				<input v-model.trim="addBuilds.fireDutyPhone" maxlength="11" class="ff-text-right" placeholder="请输入"
					placeholder-style="color:#999" type="number" />
			</view>
		</view>
		<view class="addBuilding-but">
			<view v-if="!editState" class="addBuilding-but-edit"><u-button type="primary" shape="circle"
					@click="saveBuildsClick">保存</u-button></view>
			<view class="ff-flex-between" v-else>
				<view class="addBuilding-but-list"><u-button shape="circle" @click="deleteBuildsClick"
						plain>删除</u-button></view>
				<view class="addBuilding-but-list"><u-button type="primary" shape="circle"
						@click="upateBuildsClick">保存</u-button></view>
			</view>
		</view>
		<u-toast ref="uToast" />
		<f-loading ref="loading" />
		<u-modal v-model="deleteModal" :content="deleteContent" title="温馨提示" @confirm="deleteConfirm"
			:show-cancel-button="true" :content-style="{ 'line-height': '1.5' }" />
	</view>
</template>

<script>
	export default {
		name: 'addBuilding',
		data() {
			return {
				deleteModal: false, // 删除建筑物弹框显/隐
				deleteContent: '', // 删除建筑物弹框内容
				title: '',
				editState: false,
				// 建筑物类型
				buildingTypeList: [], // 建筑物列表数据
				buildingTypeState: false, // 建筑物类型显/隐
				buildingTypeName: '', // 建筑物类型名字
				// 建筑物用途1
				buildingPurposeState1: false, // 建筑物用途1显/隐
				buildingPurposeList1: [], // 建筑物用途1
				buildingPurposeName1: '', // 选择后建筑物用途1的名字
				// 建筑物用途2
				buildingPurposeState2: false, // 建筑物用途2显/隐
				buildingPurposeList2: [], // 建筑物用途2的数组
				buildingPurposeName2: '', // 选择后建筑物用途2的名字
				// 建筑物用途3
				buildingPurposeState3: false, // 建筑物用途3显/隐
				buildingPurposeList3: [], // 建筑物用途3的数组
				buildingPurposeName3: '', // 选择后建筑物用途3的名字
				// 建筑物用途4
				buildingPurposeState4: false, // 建筑物用途4显/隐
				buildingPurposeList4: [], // 建筑物用途4
				buildingPurposeName4: '', // 选择后建筑物用途4的名字

				addBuilds: {
					buildingNewTypeTopid: '', // 建筑类型
					buildingName: '', // 建筑物名称
					buildingNewType: [], // 建筑物用途
					buildingHeight: '', // 单体建筑高度(单位米，默认保留两位小数)
					buildingUpLayers: '', // 建筑地上层数(单位层)
					buildingDownLayers: '', // 建筑地下层数(单位层)
					buildingArea: '', // 建筑物面积(m²)
					buildingAddr: '', // 建筑物地址
					buildingLatitude: '', // 建筑物所处纬度
					buildingLongitude: '', // 建筑物所处经度
					fireManageName: '', // 消防安全管理人姓名
					fireManagePhone: '', // 消防安全管理人电话
					fireDutyName: '', // 消防安全责任人姓名
					fireDutyPhone: '' // 消防安全责任人电话
				}
			};
		},
		onLoad(e) {
			// 当传参涉及到特殊字符的处理,用通过编码解码的方式处理，
			// JSON.parse(decodeURIComponent(encodeURIComponent(JSON.stringify(a)))
			// console.log('前页面传过来的数据------', JSON.parse(decodeURIComponent(e.items)));
			if (Object.keys(e).length > 0) {
				this.title = '编辑建筑物（维保）';
				this.editState = true;
				this.addBuilds = JSON.parse(decodeURIComponent(e.items));
				this.buildingTypeName = this.addBuilds.buildingNewTypeTopidName;
				this.getEditbuildingPurpose1(this.addBuilds.buildingNewTypeTopid); // 请求建筑物用途1的数据
			} else {
				this.title = '新增建筑物（维保）';
				this.editState = false;
			}
			this.getbuildingType(); // 获取建筑类别
		},
		methods: {
			// 获取建筑物详情
			async getbuildingDeatils() {
				this.$refs.loading.openLoading('加载中···'); // 打开loading动画
				const data = await this.$http.post({
					url: '/company/building/buildingType'
				});
				// console.log('获取建筑类别-----', data);
				if (data.code == 200) {
					this.buildingTypeList = data.data;
				} else {
					this.$refs.uToast.show({
						title: data.msg,
						type: 'error'
					});
				}
				this.$refs.loading.closeLoading(); // 关闭loading动画
			},
			// 获取建筑类型
			async getbuildingType() {
				this.$refs.loading.openLoading('加载中···'); // 打开loading动画
				const data = await this.$http.post({
					url: '/company/building/buildingType'
				});
				// console.log('获取建筑类别-----', data);
				if (data.code == 200) {
					this.buildingTypeList = data.data;
				} else {
					this.$refs.uToast.show({
						title: data.msg,
						type: 'error'
					});
				}
				this.$refs.loading.closeLoading(); // 关闭loading动画
			},
			// 点击显示建筑物类型弹框
			buildingTypeClick() {
				this.buildingTypeState = true;
			},
			// 确定建筑物类型
			confirmUnit(e) {
				// console.log('单位类型确定的数据----', e);
				this.addBuilds.buildingNewTypeTopid = e[0].value;
				this.buildingTypeName = e[0].label;

				this.addBuilds.buildingNewType = []; // 建筑物用途清空
				// 建筑物用途1清空
				this.buildingPurposeList1 = [];
				this.buildingPurposeName1 = '';
				// 建筑物用途2清空
				this.buildingPurposeList2 = [];
				this.buildingPurposeName2 = '';
				// 建筑物用途3清空
				this.buildingPurposeList3 = [];
				this.buildingPurposeName3 = '';
				// 建筑物用途4清空
				this.buildingPurposeList4 = [];
				this.buildingPurposeName4 = '';
				// 建筑类别名字清空
				this.buildingNewTypeTopidName = '';
				// console.log('选择建筑类别--id', e[0]);
				this.getbuildingPurpose1(e[0].value); // 请求建筑物用途的数据
			},

			// 获取建筑物用途1--------------------------------
			// 获取建筑物用途1(新建)
			async getbuildingPurpose1(id) {
				this.$refs.loading.openLoading('加载中···'); // 打开loading动画
				const data = await this.$http.get({
					url: `/company/building/buildingTypeItem/${id}`
				});
				// console.log('获取建筑物用途1---', data.data);
				if (data.code == 200) {
					this.buildingPurposeList1 = data.data;
				}

				this.$refs.loading.closeLoading(); // 关闭loading动画
			},
			// 获取建筑物用途1(编辑)
			async getEditbuildingPurpose1(id) {
				this.$refs.loading.openLoading('加载中···'); // 打开loading动画
				const data = await this.$http.get({
					url: `/company/building/buildingTypeItem/${id}`
				});
				// console.log('获取建筑物用途1---', data.data);
				if (data.code == 200) {
					this.buildingPurposeList1 = data.data;
					// 编辑建筑的时候
					if (this.editState) {
						if (this.addBuilds.ancestors != '' || this.addBuilds.ancestors != undefined) {
							if (this.buildingPurposeList1.length > 0) {
								// 建筑物用途的名字
								// 一级选择
								let PurposeId = this.addBuilds.ancestors.split(','); // 字符串转数组
								let ancestors = JSON.parse('[' + this.addBuilds.ancestors + ']'); // 把后台返回的值填充到建筑物用途数组里
								this.addBuilds.buildingNewType = ancestors.splice(1);
								this.buildingPurposeName1 = this.buildingPurposeList1.filter(a => a.id == PurposeId[
									1])[0].name;

								// 二级选择
								let dat2 = this.buildingPurposeList1.filter(a => a.id == PurposeId[1])[0].children;
								if (dat2.length > 0) {
									this.buildingPurposeList2 = dat2;
									this.buildingPurposeName2 = this.buildingPurposeList2.filter(a => a.id ==
										PurposeId[2])[0].name;

									// 三级选择
									const dat3 = this.buildingPurposeList2.filter(a => a.id == PurposeId[2])[0]
										.children;
									if (dat3.length > 0) {
										this.buildingPurposeList3 = dat3;
										this.buildingPurposeName3 = this.buildingPurposeList3.filter(a => a.id ==
											PurposeId[3])[0].name;
									}

									// 四级选择
									const dat4 = this.buildingPurposeList3.filter(a => a.id == PurposeId[3])[0]
										.children;
									if (dat4.length > 0) {
										this.buildingPurposeList4 = dat4;
										this.buildingPurposeName4 = this.buildingPurposeList4.filter(a => a.id ==
											PurposeId[4])[0].name;
									}
								}
							}
						}
					}
				}
				this.$refs.loading.closeLoading(); // 关闭loading动画
			},
			// 点击打开建筑用途1弹框
			buildingPurposeClick1() {
				this.buildingPurposeState1 = true;
			},
			// 确定建筑物类型1
			confirmPurpose1(e) {
				// console.log('确定建筑物类型1----', e);
				this.addBuilds.buildingNewType = []; // 建筑物用途清空
				this.addBuilds.buildingNewType.push(e[0].value); // 把第一个值push到建筑物用途数组里
				this.buildingPurposeName1 = e[0].label;
				// 建筑物用途2清空
				this.buildingPurposeList2 = [];
				this.buildingPurposeName2 = '';
				// 建筑物用途3清空
				this.buildingPurposeList3 = [];
				this.buildingPurposeName3 = '';
				// 建筑物用途4清空
				this.buildingPurposeList4 = [];
				this.buildingPurposeName4 = '';

				// console.log('选择建筑物类型1--id', e[0]);
				this.buildingPurposeList1.filter(res => {
					if (res.id == e[0].value) {
						this.buildingPurposeList2 = res.children;
					}
				});
				// console.log('建筑物用途2数据----', this.buildingPurposeList2);
			},
			// 点击打开建筑用途2弹框
			buildingPurposeClick2() {
				this.buildingPurposeState2 = true;
			},
			// 确定建筑物类型2
			confirmPurpose2(e) {
				// console.log('确定建筑物类型2----', e);
				this.addBuilds.buildingNewType = this.addBuilds.buildingNewType.slice(0, 1); // 建筑物用途
				this.addBuilds.buildingNewType.push(e[0].value); // 把第一个值push到建筑物用途数组里
				this.buildingPurposeName2 = e[0].label;
				// 建筑物用途3清空
				this.buildingPurposeList3 = [];
				this.buildingPurposeName3 = '';
				// 建筑物用途4清空
				this.buildingPurposeList4 = [];
				this.buildingPurposeName4 = '';

				this.buildingPurposeList2.filter(res => {
					if (res.id == e[0].value) {
						this.buildingPurposeList3 = res.children;
					}
				});
				// console.log('建筑物用途3数据-----', this.buildingPurposeList3);
			},
			// 点击打开建筑用途3弹框
			buildingPurposeClick3() {
				this.buildingPurposeState3 = true;
			},
			// 确定建筑物类型3
			confirmPurpose3(e) {
				// console.log('确定建筑物类型3----', e);
				this.addBuilds.buildingNewType = this.addBuilds.buildingNewType.slice(0, 2); // 建筑物用途
				this.addBuilds.buildingNewType.push(e[0].value); // 把第一个值push到建筑物用途数组里
				this.buildingPurposeName3 = e[0].label;
				// 建筑物用途4清空
				this.buildingPurposeList4 = [];
				this.buildingPurposeName4 = '';

				this.buildingPurposeList3.filter(res => {
					if (res.id == e[0].value) {
						this.buildingPurposeList4 = res.children;
					}
				});
				// console.log('建筑物用途4数据-----', this.buildingPurposeList4);
			},
			// 点击打开建筑用途4弹框
			buildingPurposeClick4() {
				this.buildingPurposeState4 = true;
			},
			// 确定建筑物类型4
			confirmPurpose4(e) {
				// console.log('确定建筑物类型3----', e);
				this.addBuilds.buildingNewType = this.addBuilds.buildingNewType.slice(0, 3); // 建筑物用途
				this.addBuilds.buildingNewType.push(e[0].value); // 把第一个值push到建筑物用途数组里
				this.buildingPurposeName4 = e[0].label;
			},

			// 选择建筑物地址
			unitRegisterAddress() {
				let that = this;
				uni.chooseLocation({
					success: function(res) {
						// console.log('获取建筑物地址地址数据---------', res);
						that.addBuilds.buildingAddr = that.$check.emptySpecial(res.address); // 单位注册地址，清除特殊字符
						that.addBuilds.buildingLatitude = res.latitude; // 单位纬度
						that.addBuilds.buildingLongitude = res.longitude; // 单位经度
					},
					fail(error) {
						// console.log('位置定位失败返回----', error);
						that.locationModal = true;
					}
				});
			},
			// 新建建筑物--------------------保存数据
			saveBuildsClick() {
				// console.log('保存数据-----', this.addBuilds, this.buildingPurposeList1);
				if (!this.addBuilds.buildingName) {
					this.$refs.uToast.show({
						title: '请输入建筑物名称',
						type: 'error'
					});
					return;
				}
				if (this.$check.hasSpecialChar(this.addBuilds.buildingName)) {
					uni.showModal({
						title: '温馨提示',
						content: '建筑物名称不允许含有特殊字符&、@、*、？等，请修改后再试。',
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {}
						}
					})
					return
				}
				if (!this.addBuilds.buildingNewTypeTopid) {
					this.$refs.uToast.show({
						title: '请选择建筑物类型',
						type: 'error'
					});
					return;
				}
				if (this.buildingPurposeList1 != null) {
					if (this.addBuilds.buildingNewType == '') {
						this.$refs.uToast.show({
							title: '建筑物用途不能为空',
							type: 'error'
						});
						return false;
					}
				}
				if (!this.addBuilds.buildingAddr) {
					this.$refs.uToast.show({
						title: '请选择建筑物地址',
						type: 'error'
					});
					return;
				}
				let t1 = /(^\+?[0-9][0-9]*$)|(^(\d+\.\d{1,2})$)/.test(this.addBuilds.buildingHeight);
				if (!t1) {
					this.$refs.uToast.show({
						title: '建筑物高度不能为负数，且允许保留小数点后2位',
						type: 'error'
					});
					return;
				}

				let t4 = /(^\+?[0-9][0-9]*$)|(^(\d+\.\d{1,2})$)/.test(this.addBuilds.buildingArea);
				// console.log('建筑面积');
				if (!t4) {
					this.$refs.uToast.show({
						title: '建筑面积不能为负数，且允许保留小数点后2位',
						type: 'error'
					});
					return;
				}
				let t2 = /^(0|[1-9][0-9]*)$/.test(this.addBuilds.buildingUpLayers);
				if (!t2) {
					this.$refs.uToast.show({
						title: '请正确填写建筑地上层数（0及0以上的整数)',
						type: 'error'
					});
					return;
				}
				let t3 = /^(0|[1-9][0-9]*)$/.test(this.addBuilds.buildingDownLayers);
				if (!t3) {
					this.$refs.uToast.show({
						title: '请正确填写建筑地下层数（0及0以上的整数)',
						type: 'error'
					});
					return;
				}
				// if (!this.addBuilds.fireManageName) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入消防安全管理人姓名',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// let t5 = /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.addBuilds.fireManagePhone);
				// if (!t5) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入正确的消防安全管理人手机号',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// if (!this.addBuilds.fireDutyName) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入消防安全责任人姓名',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// let t6 = /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.addBuilds.fireDutyPhone);
				// if (!t6) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入正确的消防安全责任人手机号',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				this.$refs.loading.openLoading('提交中···'); // 打开loading动画
				if (this.addBuilds.buildingNewType) {
					var buildingNewType = this.addBuilds.buildingNewType.pop(); // 方法用于删除并返回数组的最后一个元素。
				}
				let datas = {
					buildingName: this.addBuilds.buildingName,
					buildingHeight: this.addBuilds.buildingHeight,
					buildingUpLayers: this.addBuilds.buildingUpLayers,
					buildingDownLayers: this.addBuilds.buildingDownLayers,
					buildingArea: this.addBuilds.buildingArea,
					buildingAddr: this.addBuilds.buildingAddr,
					buildingLatitude: this.addBuilds.buildingLatitude,
					buildingLongitude: this.addBuilds.buildingLongitude,
					buildingNewType: buildingNewType,
					buildingNewTypeTopid: this.addBuilds.buildingNewTypeTopid,
					fireManageName: this.addBuilds.fireManageName, // 消防安全管理人姓名
					fireManagePhone: this.addBuilds.fireManagePhone, // 消防安全管理人电话
					fireDutyName: this.addBuilds.fireDutyName, // 消防安全责任人姓名
					fireDutyPhone: this.addBuilds.fireDutyPhone // 消防安全责任人电话
				};
				this.$http
					.post({
						url: '/company/building/add',
						data: datas
					})
					.then(res => {
						// console.log('提交保存信息', res);
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'success'
							});
							let that = this;
							setTimeout(() => {
								that.$pageJump.reLaunch(
									'/pages/maintenance/public/personal/building/buildingList');
							}, 500);
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
						this.$refs.loading.closeLoading(); // 关闭loading动画
					});
			},
			// 编辑建筑物--------------------更新数据
			upateBuildsClick() {
				if (!this.addBuilds.buildingName) {
					this.$refs.uToast.show({
						title: '请输入建筑物名称',
						type: 'error'
					});
					return false;
				}
				if (this.$check.hasSpecialChar(this.addBuilds.buildingName)) {
					uni.showModal({
						title: '温馨提示',
						content: '建筑物名称不允许含有特殊字符&、@、*、？等，请修改后再试。',
						confirmColor: '#3178FF',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {}
						}
					})
					return
				}
				if (!this.addBuilds.buildingNewTypeTopid) {
					this.$refs.uToast.show({
						title: '请选择建筑物类型',
						type: 'error'
					});
					return;
				}
				// console.log('this.addBuilds.buildingNewType', this.addBuilds.buildingNewType, this.buildingPurposeList1)
				if (this.buildingPurposeList1 != null) {
					if (!this.addBuilds.buildingNewType) {
						this.$refs.uToast.show({
							title: '建筑物用途不能为空',
							type: 'error'
						});
						return false;
					}
				}
				if (!this.addBuilds.buildingAddr) {
					this.$refs.uToast.show({
						title: '请选择建筑物地址',
						type: 'error'
					});
					return;
				}
				let t1 = /(^\+?[0-9][0-9]*$)|(^(\d+\.\d{1,2})$)/.test(this.addBuilds.buildingHeight);
				if (!t1) {
					this.$refs.uToast.show({
						title: '建筑物高度不能为负数，且允许保留小数点后2位',
						type: 'error'
					});
					return;
				}

				let t4 = /(^\+?[0-9][0-9]*$)|(^(\d+\.\d{1,2})$)/.test(this.addBuilds.buildingArea);
				// console.log('建筑面积');
				if (!t4) {
					this.$refs.uToast.show({
						title: '建筑面积不能为负数，且允许保留小数点后2位',
						type: 'error'
					});
					return;
				}
				let t2 = /^(0|[1-9][0-9]*)$/.test(this.addBuilds.buildingUpLayers);
				if (!t2) {
					this.$refs.uToast.show({
						title: '请正确填写建筑地上层数（0及0以上的整数)',
						type: 'error'
					});
					return;
				}
				let t3 = /^(0|[1-9][0-9]*)$/.test(this.addBuilds.buildingDownLayers);
				if (!t3) {
					this.$refs.uToast.show({
						title: '请正确填写建筑地下层数（0及0以上的整数)',
						type: 'error'
					});
					return;
				}
				// if (!this.addBuilds.fireManageName) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入消防安全管理人姓名',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// let t5 = /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.addBuilds.fireManagePhone);
				// if (!t5) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入正确的消防安全管理人手机号',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// if (!this.addBuilds.fireDutyName) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入消防安全责任人姓名',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				// let t6 = /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(this.addBuilds.fireDutyPhone);
				// if (!t6) {
				// 	this.$refs.uToast.show({
				// 		title: '请输入正确的消防安全责任人手机号',
				// 		type: 'error'
				// 	});
				// 	return;
				// }
				this.$refs.loading.openLoading('更新中···'); // 打开loading动画
				if (this.addBuilds.buildingNewType) {
					var buildingNewType = this.addBuilds.buildingNewType.pop(); // 方法用于删除并返回数组的最后一个元素。
				}
				let datas = {
					buildingName: this.addBuilds.buildingName,
					buildingHeight: this.addBuilds.buildingHeight,
					buildingUpLayers: this.addBuilds.buildingUpLayers,
					buildingDownLayers: this.addBuilds.buildingDownLayers,
					buildingArea: this.addBuilds.buildingArea,
					buildingAddr: this.addBuilds.buildingAddr,
					buildingLatitude: this.addBuilds.buildingLatitude,
					buildingLongitude: this.addBuilds.buildingLongitude,
					buildingNewType: buildingNewType,
					buildingNewTypeTopid: this.addBuilds.buildingNewTypeTopid,
					fireManageName: this.addBuilds.fireManageName, // 消防安全管理人姓名
					fireManagePhone: this.addBuilds.fireManagePhone, // 消防安全管理人电话
					fireDutyName: this.addBuilds.fireDutyName, // 消防安全责任人姓名
					fireDutyPhone: this.addBuilds.fireDutyPhone // 消防安全责任人电话
				};
				this.$http
					.post({
						url: `/company/building/upd/${this.addBuilds.buildingId}`,
						data: datas
					})
					.then(res => {
						// console.log('编辑----更新建筑物返回-----', res);
						if (res.code == 200) {
							this.$refs.loading.closeLoading(); // 关闭loading动画
							this.$refs.uToast.show({
								title: res.msg,
								type: 'success'
							});
							let that = this;
							setTimeout(() => {
								that.$pageJump.reLaunch(
									'/pages/maintenance/public/personal/building/buildingList');
							}, 500);
						} else {
							this.$refs.loading.closeLoading(); // 关闭loading动画
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							});
						}
					});
			},
			// 编辑建筑物--------------------删除数据
			deleteBuildsClick() {
				this.deleteModal = true;
				this.deleteContent = `确定删除${this.addBuilds.buildingName}吗？`;
			},
			deleteConfirm() {
				this.$refs.loading.openLoading('删除中···'); // 打开loading动画
				this.$http.post({
					url: `/company/building/del/${this.addBuilds.buildingId}`
				}).then(res => {
					// console.log('编辑----删除当前建筑物返回数据----', res);
					if (res.code == 200) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'success'
						});
						let that = this;
						setTimeout(() => {
							that.$pageJump.reLaunch(
								'/pages/maintenance/public/personal/building/buildingList');
						}, 500);
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						});
					}
					this.$refs.loading.closeLoading(); // 关闭loading动画
				});
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss" scoped>
	.addBuilding {
		.companyInfo-content-title {
			width: 331rpx;
		}

		&-but {
			&-edit {
				width: 90%;
				margin: 10% 5% 15%;
				padding-bottom: 80rpx;
			}

			&-list {
				width: 46%;
				margin: 10% 3%;

				/deep/.u-size-default {
					height: 90rpx !important;
					line-height: 90rpx !important;
					color: #95979e;
					border-color: #95979e;
				}

				/deep/.u-btn--primary {
					color: #ffffff !important;
					border-color: #3178ff !important;
					background-color: #3178ff !important;
				}
			}
		}
	}
</style>